package com.qwc.blog.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qwc.blog.entity.Tag;
import com.qwc.blog.mapper.TagMapper;
import com.qwc.blog.service.ITagService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 标签表 服务实现类
 * </p>
 *
 * @author qwc
 * @since 2022-01-24
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements ITagService {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean removeTagAndArticleTagByIds(List<Integer> asList) {
        int i = baseMapper.deleteBatchIds(asList);
        int l = baseMapper.deleteArticleTagByTagIds(asList);
        return i+l>0;
    }

    @Override
    @Cacheable(cacheNames = "tag")
    public List<Tag> listFromCache() {
        return baseMapper.selectList(Wrappers.emptyWrapper());
    }
}
